<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <p>转载地址：<a href=https://zhuanlan.zhihu.com/p/34173506 target="_blank">https://zhuanlan.zhihu.com/p/34173506</p>
    <button class=button><span>鼠标悬停效果</span></button>

    <script>
        // 监听鼠标移动
        document.querySelector('.button').onmousemove = (e) => {
            const x = e.pageX - e.target.offsetLeft
            const y = e.pageY - e.target.offsetTop
            e.target.style.setProperty('--x', `${x}px`)
            e.target.style.setProperty('--y', `${y}px`)
        }
    </script>
</body>

</html>